// import moment from 'moment' //导入文件

/**
 * 
 * getDate
 * 例子
 * 一至五 
 * 周六周日   
 * 周几  下标   起始位置    结束位置      当前日期
 *  一    7      5          11           2022-02-21
 *  二    7      4          10           2022-02-22
 *  三    7      3          9            2022-02-23
 *  四    7      2          8            2022-02-24
 *  五    7      1          7            2022-02-25
 * ------------------------------------------------
 *  六    7      7          13           2022-02-26
 *  日    7      6          12           2022-02-27
 */

/**
 * 
 * @param {*} date 日期  2022-02-21
 * @param {*} flag 标识
 * @returns Array
 */
function getDate(flag = true) {
    let d = new Date()
    let w = d.getDay()
    let checkDate = []
    let startStr = '00:00:00'
    let endStr = '23:59:59'
    let startIndx = 0
    let endIndex = 0

    let tag = [...new Set([..._getDateSection(flag).reverse(), ..._getDateSection(!flag)])]
    console.log(w, tag)

    switch (w) {
        case 1:
            startIndx = 5
            endIndex = 11
            break;
        case 2:
            startIndx = 4
            endIndex = 10
            break;
        case 3:
            startIndx = 3
            endIndex = 9
            break;
        case 4:
            startIndx = 2
            endIndex = 8
            break;
        case 5:
            startIndx = 1
            endIndex = 7
            break;
        case 6:
            startIndx = 7
            endIndex = 13
            break;
        default:
            startIndx = 6
            endIndex = 12
            break;
    }
    checkDate.push(tag[startIndx] + ' ' + startStr, tag[endIndex] + ' ' + endStr)
    // checkDate.push(moment(tag[startIndx]).format('YYYY-MM-DD') + ' ' + startStr, moment(tag[endIndex]).format('YYYY-MM-DD') + ' ' + endStr)
    return checkDate
}


/**
 * 修改按钮置灰
 * @param {*} record 
 * @returns bool
 */
function setBtn(record,key='billTimeEnd') {
    var timestamp1 = new Date().getTime()
    var timestamp2 = new Date(record[key]).getTime()

    if (timestamp1 < timestamp2) {
        return true
    } else {
        return false
    }
}




/**
 * _getDateSection()
 * 获取某天之前或之后数组
 * @param {*} date 日期 2022-02-21
 * @param {*} flag 标识  之前或之后
 * @returns Array
 */
function _getDateSection(flag = true) {
    var base = new Date().getTime()
    var oneDay = 24 * 3600 * 1000
    var date = []
    var data = [Math.random() * 300]
    var time = new Date(base)
    date.push([time.getFullYear(), time.getMonth() + 1, time.getDate()].join('-'))
    for (var i = 1; i < 8; i++) {
        var now = new Date(flag ? (base -= oneDay) : (base += oneDay))
        let y = now.getFullYear()
        let m = now.getMonth() + 1
        let d = now.getDate()
        date.push([y, m, d].join('-'))
        data.push(Math.round((Math.random() - 0.5) * 20 + data[i - 1]))
    }
    var newdate = date
    return newdate
}


export {
    getDate,
    setBtn
}